package com.indexingsystem.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.indexingsystem.boss.Vo.OrderExportOtherResQueryVo;
import com.indexingsystem.boss.Vo.OrderOtherResVo;
import com.indexingsystem.boss.Vo.OrderResultVo;
import com.indexingsystem.boss.Vo.ResCategoryRelationsVo;
import com.indexingsystem.boss.Vo.ResourceCheckVo;
import com.indexingsystem.boss.Vo.ResourceRelationsReqVo;
import com.indexingsystem.boss.Vo.ResourceRelationsVo;
import com.indexingsystem.boss.Vo.ResourcesReqVo;
import com.indexingsystem.boss.Vo.ResourcesVo;
import com.indexingsystem.boss.Vo.StatusList;
import com.indexingsystem.boss.admin.mapper.ArticlesMapper;
import com.indexingsystem.boss.admin.mapper.AuditLogsMapper;
import com.indexingsystem.boss.admin.mapper.BooksMapper;
import com.indexingsystem.boss.admin.mapper.DhMagazinesMlMapper;
import com.indexingsystem.boss.admin.mapper.DhResourceauditlogsMapper;
import com.indexingsystem.boss.admin.mapper.GamesMapper;
import com.indexingsystem.boss.admin.mapper.MagazinesMapper;
import com.indexingsystem.boss.admin.mapper.ResCategoryRelationsMapper;
import com.indexingsystem.boss.admin.mapper.ResourceCategorsMapper;
import com.indexingsystem.boss.admin.mapper.ResourceRelationsMapper;
import com.indexingsystem.boss.admin.mapper.ResourceTypeMapper;
import com.indexingsystem.boss.admin.mapper.ResourcesMapper;
import com.indexingsystem.boss.admin.mapper.VideosMapper;
import com.indexingsystem.boss.common.PagedResult;
import com.indexingsystem.boss.entity.AuditLogs;
import com.indexingsystem.boss.entity.Books;
import com.indexingsystem.boss.entity.DhResourceauditlogs;
import com.indexingsystem.boss.entity.Games;
import com.indexingsystem.boss.entity.Magazines;
import com.indexingsystem.boss.entity.ResCategoryRelations;
import com.indexingsystem.boss.entity.ResourceCategors;
import com.indexingsystem.boss.entity.ResourceInfo;
import com.indexingsystem.boss.entity.ResourceRelationInfo;
import com.indexingsystem.boss.entity.ResourceRelations;
import com.indexingsystem.boss.entity.ResourceType;
import com.indexingsystem.boss.entity.Resources;
import com.indexingsystem.boss.entity.Videos;
import com.indexingsystem.boss.utils.BeanUtils;
import com.indexingsystem.boss.utils.DateUtil;
import com.indexingsystem.boss.utils.InstitutionLoadUtils;
import com.indexingsystem.boss.utils.StringUtil;
import com.indexingsystem.db.mongoDB.comon.MongoTableName;
import com.indexingsystem.db.mongoDB.impl.ResourceCategorsResListMongo;
import com.indexingsystem.db.mongoDB.impl.ResourceCommonMongo;
import com.indexingsystem.db.mongoDB.po.ResourceCategorsResPo;
import com.indexingsystem.system.service.IResourceService;
import com.indexingsystem.system.service.IdhTodayStorageInfosService;

@Service
public class ResourcesServiceImpl implements IResourceService {

	@Resource
	private ResourcesMapper				resourcesMapper;

	@Resource
	private AuditLogsMapper				auditLogsMapper;

	@Resource
	private ResourceRelationsMapper		resourceRelationsMapper;

	@Resource
	private IdhTodayStorageInfosService	todayStorageInfosDao;

	@Resource
	private DhResourceauditlogsMapper	dhResourceauditlogsMapper;

	@Resource
	private ResourceTypeMapper			resourceTypeMapper;

	@Resource
	private DhMagazinesMlMapper			dhMagazinesMlMapper;

	@Resource
	private ResCategoryRelationsMapper	resCategoryRelationsMapper;

	@Resource
	private ArticlesMapper				articlesMapper;

	@Resource
	private MagazinesMapper				magazinesMapper;

	@Resource
	private ResourceCategorsMapper		resourceCategorsMapper;

	@Resource
	private BooksMapper					booksMapper;

	@Resource
	private VideosMapper				videosMapper;

	@Resource
	private GamesMapper					gamesMapper;

	/**
	 * 获取资源未关联列表数据长度
	 */
	public Integer getLeftResourceInfoCount(ResourcesReqVo resourcesReqVo) {
		return resourcesMapper.getLeftResourceInfoCount( resourcesReqVo );
	}

	/**
	 * 获取资源已关联列表信息长度
	 * 
	 * @param resourcesReqVo
	 * @return
	 */
	public Integer getRightResourceInfoCount(ResourceRelationsReqVo resourceRelationsReqVo) {
		return resourcesMapper.getRightResourceInfoCount( resourceRelationsReqVo );
	}

	/**
	 * 获取资源未关联列表信息
	 * 
	 * @param resourcesReqVo
	 * @return
	 */
	public PagedResult<ResourceInfo> getLeftResourceInfo(ResourcesReqVo resourcesReqVo) {
		Integer pageNumber = resourcesReqVo.getPageNumber() == null ? 1 : resourcesReqVo.getPageNumber();
		Integer pageSize = resourcesReqVo.getPageSize() == null ? 10 : resourcesReqVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNumber, pageSize );
		return BeanUtils.toPagedResult( resourcesMapper.getLeftResourceInfo( resourcesReqVo ) );
	}

	/**
	 * 获取已资源已关联列表信息
	 * 
	 * @param resourceRelationsReqVo
	 * @return
	 */
	public PagedResult<ResourceRelationInfo> getRightResourceInfo(ResourceRelationsReqVo resourceRelationsReqVo) {
		Integer pageNumber = resourceRelationsReqVo.getPageNumber() == null ? 1 : resourceRelationsReqVo.getPageNumber();
		Integer pageSize = resourceRelationsReqVo.getPageSize() == null ? 10 : resourceRelationsReqVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNumber, pageSize );
		return BeanUtils.toPagedResult( resourcesMapper.getRightResourceInfo( resourceRelationsReqVo ) );
	}

	/**
	 * 建立资源关系
	 * 
	 * @param resourceCheckVo
	 * @return
	 */
	public int addRelation(List<ResourceCheckVo> resourceCheckVo) {
		return resourcesMapper.addRelation( resourceCheckVo );
	}

	/**
	 * 撤销资源关系
	 * 
	 * @param resourceCheckVo
	 * @return
	 */
	public int deleteRelation(List<String> resourceRelationId) {
		return resourcesMapper.deleteRelation( resourceRelationId );
	}

	/**
	 * 通过资源id删除资源信息.
	 */
	@Override
	public int deleteByPrimaryKey(String resId) {
		return resourcesMapper.deleteByPrimaryKey( resId );
	}

	/**
	 * 新增资源信息
	 */
	@Override
	public int insertSelective(Resources record) {
		return resourcesMapper.insertSelective( record );
	}

	/**
	 * 通过资源id查询资源信息.
	 */
	@Override
	public Resources selectByPrimaryKey(String resId) {
		return resourcesMapper.selectByPrimaryKey( resId );
	}

	/**
	 * 根据条件修改资源信息.
	 */
	@Override
	public int updateByPrimaryKeySelective(Resources record) {
		return resourcesMapper.updateByPrimaryKeySelective( record );
	}

	/**
	 * 资源分类中资源列表查询显示列表.
	 */
	@Override
	public PagedResult<ResourcesVo> selectResCategorsByResList(ResourcesVo resourcesVo) {
		Integer pageNo = resourcesVo.getPageNumber() == null ? 1 : resourcesVo.getPageNumber();
		Integer pageSize = resourcesVo.getPageSize() == null ? 10 : resourcesVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNo, pageSize );
		return BeanUtils.toPagedResult( resourcesMapper.selectResCategorsByResList( resourcesVo ) );
	}

	/**
	 * 栏目中资源列表查询显示列表.
	 */
	@Override
	public PagedResult<ResourcesVo> selectMenusByResList(ResourcesVo resourcesVo) {
		Integer pageNo = resourcesVo.getPageNumber() == null ? 1 : resourcesVo.getPageNumber();
		Integer pageSize = resourcesVo.getPageSize() == null ? 10 : resourcesVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage( pageNo, pageSize );
		return BeanUtils.toPagedResult( resourcesMapper.selectMenusByResList( resourcesVo ) );
	}

	/**
	 * 获取资源列表总数量.
	 */
	@Override
	public Integer getResourcesListCount() {
		return resourcesMapper.getResourcesListCount();
	}

	/**
	 * 通过资源分类id查询未关联的资源列表总数量.
	 * 
	 * @param resourcesVo
	 * @return
	 */
	@Override
	public Integer getResourcesByResCategoryIdListCount(ResourcesVo resourcesVo) {
		return resourcesMapper.getResourcesByResCategoryIdListCount( resourcesVo );
	}

	/**
	 * 通过栏目id查询未关联的资源列表总数量.
	 * 
	 * @param resourcesVo
	 * @return
	 */
	@Override
	public Integer getResourcesByMenusIdListCount(ResourcesVo resourcesVo) {
		return resourcesMapper.getResourcesByMenusIdListCount( resourcesVo );
	}

	/**
	 * 批量审核资源操作.
	 * 
	 * @param list
	 * @return
	 */
	@Override
	public Integer batchUpdateResourceWithList(List<AuditLogs> auditLogsList, List<StatusList> list, List<DhResourceauditlogs> dhResourceauditlogsList)
			throws Exception {
		int result = 0;
		int optStatus = 0;
		List<String> resIdList = null;
		Resources resources = null;
		ResourceType resourceType = null;
		if (null != list && list.size() > 0) {

			optStatus = list.get( 0 ).getStatus();
			resIdList = new ArrayList<String>();
			for (StatusList statusList : list) {
				if (!resIdList.contains( statusList.getId() )) {
					resIdList.add( statusList.getId() );
				}
			}

			Resources resourcesObj = resourcesMapper.selectByPrimaryKey( resIdList.get( 0 ) );
			if (null != resourcesObj) {
				resourceType = resourceTypeMapper.selectByPrimaryKey( resourcesObj.getResTypeId() );
			}

			// 1、第一步批量审核状态变更
			result = resourcesMapper.batchUpdateResourceWithList( list );

			if (null != dhResourceauditlogsList && dhResourceauditlogsList.size() > 0) {
				for (DhResourceauditlogs resourceAuditLogs : dhResourceauditlogsList) {
					dhResourceauditlogsMapper.updateByPrimaryKeySelective( resourceAuditLogs );
				}
			}
			// 入库审核状态批量变更
			// dhResourceauditlogsMapper.batchAddResourceAuditLogs(
			// dhResourceauditlogsList );
			// 2、第二步批量修改审核日志
			if (null != auditLogsList && auditLogsList.size() > 0) {
				for (AuditLogs auditLogs : auditLogsList) {
					auditLogsMapper.updateByPrimaryKeySelective( auditLogs );
				}
			}

			// 批量更新入库明细表审核状态
			todayStorageInfosDao.updateTodayStorageInfosByResIdList( list );

			// auditLogsMapper.batchAddAuditLogs( auditLogsList );
			// 清理资源关系
			if (optStatus != 1) {
				if (null != resIdList && resIdList.size() > 0) {
					// // 审核不通过，删除缓存
					// ResCategoryRelations resCategoryRelations = null;
					// for (String resId : resIdList) {
					// List<ResCategoryRelationsVo> relationsList =
					// resCategoryRelationsMapper.getResCategoryRelationsByResId(
					// resId );
					// for (ResCategoryRelationsVo resCategoryRelationsVo :
					// relationsList) {
					// resCategoryRelations = new ResCategoryRelations();
					// resCategoryRelations.setResCategoryId(
					// resCategoryRelationsVo.getResCategoryId() );
					// resCategoryRelations.setResId(
					// resCategoryRelationsVo.getResId() );
					// ResourceCategorsResListMongo.deleteResCategoryRelationsById(
					// resCategoryRelations );
					// }
					// }

					resourceRelationsMapper.deleteBatchResourceRelationsByResIdList( resIdList );
					resourceRelationsMapper.deleteBatchResourceRelationsRightByResIdList( resIdList );

					// 3、清理资源分类关系表
					resCategoryRelationsMapper.deleteResBatchCategoryRelationsByResId( resIdList );

				}
			}
			// } else {
			// // 批量审核通过，添加缓存
			// // 区分资源类型
			// List<String> resCateRelationsParent = null;
			// List<String> resCateRelationsChair = null;
			// List<String> resCateRelationsAll = null;
			// List<ResourceCategorsResPo> resourceCategorsResPoList = null;
			// if (null != resourcesObj) {
			// if (null != resourceType) {
			// if (resourceType.getResTable().equals( "Magazines" )) {
			// resCateRelationsParent = new ArrayList<String>();
			// resCateRelationsChair = new ArrayList<String>();
			// resCateRelationsAll = new ArrayList<String>();
			// resourceCategorsResPoList = new
			// ArrayList<ResourceCategorsResPo>();
			// for (String resId : resIdList) {
			// List<ResCategoryRelationsVo> relationsList =
			// resCategoryRelationsMapper.getResCategoryRelationsByResId( resId
			// );
			// for (ResCategoryRelationsVo resCategoryRelations : relationsList)
			// {
			// if (!resCategoryRelations.getParentId().equals( "0" )) {
			// if (!resCateRelationsParent.contains(
			// resCategoryRelations.getParentId() )) {
			// resCateRelationsParent.add( resCategoryRelations.getParentId() );
			// }
			// }
			// if (!resCateRelationsChair.contains(
			// resCategoryRelations.getResCategoryId() )) {
			// resCateRelationsChair.add(
			// resCategoryRelations.getResCategoryId() );
			// }
			// }
			// for (String resCategoryIdChair : resCateRelationsChair) {
			// if (!resCateRelationsParent.contains( resCategoryIdChair )) {
			// resCateRelationsAll.add( resCategoryIdChair );
			// }
			// }
			//
			// // resCateRelationsAll 资源分类关系
			// // 加入缓存
			// if (null != resCateRelationsAll && resCateRelationsAll.size() >
			// 0) {
			// for (String resCateRela : resCateRelationsAll) {
			//
			// ResourceCategorsResPo resourceCategorsResPo = new
			// ResourceCategorsResPo();
			// ResourceCategors resourceCategors =
			// resourceCategorsMapper.selectByPrimaryKey( resCateRela );
			// resources = resourcesMapper.selectByPrimaryKey( resId );//
			// 通过资源Id查询资源信息
			//
			// Magazines magazines = magazinesMapper.selectByPrimaryKey(
			// resources.getResId() );
			// resourceCategorsResPo.setThumbnail( magazines.getFrontCover() );
			// resourceCategorsResPo.setResType( 1 );
			// String publishDate = magazines.getYear() + "年" +
			// magazines.getMonth() + "月" + "第"
			// + magazines.getPeriodOfTime() + "期";
			// String month = "";
			// if (magazines.getMonth() < 10) {
			// month = "0" + magazines.getMonth().toString();
			// } else {
			// month = magazines.getMonth().toString();
			// }
			// String dateValue = magazines.getYear() + "-" + month + "-" +
			// "01";
			// resourceCategorsResPo.setDatePx(
			// DateUtil.parseFormatToPublishDate( dateValue ) );
			// resourceCategorsResPo.setPublishDate( publishDate );
			//
			// resourceCategorsResPo.setResId( resources.getResId() );
			// resourceCategorsResPo.setResName( resources.getResName() );
			// resourceCategorsResPo.setResTypeId( resources.getResTypeId() );
			// resourceCategorsResPo.setResCategoryId(
			// resourceCategors.getResCategoryId() );
			// resourceCategorsResPo.setResCategoryName(
			// resourceCategors.getResName() );
			// resourceCategorsResPo.setResTable( "Magazine" );
			// resourceCategorsResPo.setStatus( resources.getStatus() );
			//
			// if (!resourceCategorsResPoList.contains( resourceCategorsResPo ))
			// {
			// resourceCategorsResPoList.add( resourceCategorsResPo );
			// }
			// }
			// // 存储更新到mongo
			// if (null != resourceCategorsResPoList &&
			// resourceCategorsResPoList.size() > 0) {
			// ResourceCategorsResListMongo.addResourceCategorsResList(
			// resourceCategorsResPoList );
			// }
			// }
			// }
			// } else if (resourceType.getResTable().equals( "Books" )) {
			// // 图书审核通过
			// resCateRelationsParent = new ArrayList<String>();
			// resCateRelationsChair = new ArrayList<String>();
			// resCateRelationsAll = new ArrayList<String>();
			// resourceCategorsResPoList = new
			// ArrayList<ResourceCategorsResPo>();
			// for (String resId : resIdList) {
			// List<ResCategoryRelationsVo> relationsList =
			// resCategoryRelationsMapper.getResCategoryRelationsByResId( resId
			// );
			// for (ResCategoryRelationsVo resCategoryRelations : relationsList)
			// {
			// if (!resCategoryRelations.getParentId().equals( "0" )) {
			// if (!resCateRelationsParent.contains(
			// resCategoryRelations.getParentId() )) {
			// resCateRelationsParent.add( resCategoryRelations.getParentId() );
			// }
			// }
			// if (!resCateRelationsChair.contains(
			// resCategoryRelations.getResCategoryId() )) {
			// resCateRelationsChair.add(
			// resCategoryRelations.getResCategoryId() );
			// }
			// }
			// for (String resCategoryIdChair : resCateRelationsChair) {
			// if (!resCateRelationsParent.contains( resCategoryIdChair )) {
			// resCateRelationsAll.add( resCategoryIdChair );
			// }
			// }
			//
			// // resCateRelationsAll 资源分类关系
			// // 加入缓存
			// if (null != resCateRelationsAll && resCateRelationsAll.size() >
			// 0) {
			// for (String resCateRela : resCateRelationsAll) {
			// ResourceCategorsResPo resourceCategorsResPo = new
			// ResourceCategorsResPo();
			// ResourceCategors resourceCategors =
			// resourceCategorsMapper.selectByPrimaryKey( resCateRela );
			// resources = resourcesMapper.selectByPrimaryKey( resId );//
			// 通过资源Id查询资源信息
			//
			// Books books = booksMapper.selectByPrimaryKey(
			// resources.getResId() );
			// resourceCategorsResPo.setThumbnail( books.getFrontCover() );
			// resourceCategorsResPo.setResType( 2 );
			// resourceCategorsResPo.setDatePx(
			// DateUtil.parseFormatToPublishDate( resources.getPublishDate() )
			// );
			// resourceCategorsResPo.setPublishDate( resources.getPublishDate()
			// );
			//
			// resourceCategorsResPo.setResId( resources.getResId() );
			// resourceCategorsResPo.setResName( resources.getResName() );
			// resourceCategorsResPo.setResTypeId( resources.getResTypeId() );
			// resourceCategorsResPo.setResCategoryId(
			// resourceCategors.getResCategoryId() );
			// resourceCategorsResPo.setResCategoryName(
			// resourceCategors.getResName() );
			// resourceCategorsResPo.setResTable( "Books" );
			// resourceCategorsResPo.setStatus( resources.getStatus() );
			//
			// if (!resourceCategorsResPoList.contains( resourceCategorsResPo ))
			// {
			// resourceCategorsResPoList.add( resourceCategorsResPo );
			// }
			// }
			// // 存储更新到mongo
			// if (null != resourceCategorsResPoList &&
			// resourceCategorsResPoList.size() > 0) {
			// ResourceCategorsResListMongo.addResourceCategorsResList(
			// resourceCategorsResPoList );
			// }
			// }
			// }
			//
			// } else if (resourceType.getResTable().equals( "Videos" ) ||
			// resourceType.getResTable().equals( "Pictures" )) {
			// // 视频和图片审核通过
			// resCateRelationsParent = new ArrayList<String>();
			// resCateRelationsChair = new ArrayList<String>();
			// resCateRelationsAll = new ArrayList<String>();
			// resourceCategorsResPoList = new
			// ArrayList<ResourceCategorsResPo>();
			// for (String resId : resIdList) {
			// List<ResCategoryRelationsVo> relationsList =
			// resCategoryRelationsMapper.getResCategoryRelationsByResId( resId
			// );
			// for (ResCategoryRelationsVo resCategoryRelations : relationsList)
			// {
			// if (!resCategoryRelations.getParentId().equals( "0" )) {
			// if (!resCateRelationsParent.contains(
			// resCategoryRelations.getParentId() )) {
			// resCateRelationsParent.add( resCategoryRelations.getParentId() );
			// }
			// }
			// if (!resCateRelationsChair.contains(
			// resCategoryRelations.getResCategoryId() )) {
			// resCateRelationsChair.add(
			// resCategoryRelations.getResCategoryId() );
			// }
			// }
			// for (String resCategoryIdChair : resCateRelationsChair) {
			// if (!resCateRelationsParent.contains( resCategoryIdChair )) {
			// resCateRelationsAll.add( resCategoryIdChair );
			// }
			// }
			//
			// // resCateRelationsAll 资源分类关系
			// // 加入缓存
			// if (null != resCateRelationsAll && resCateRelationsAll.size() >
			// 0) {
			// for (String resCateRela : resCateRelationsAll) {
			// ResourceCategorsResPo resourceCategorsResPo = new
			// ResourceCategorsResPo();
			// ResourceCategors resourceCategors =
			// resourceCategorsMapper.selectByPrimaryKey( resCateRela );
			// resources = resourcesMapper.selectByPrimaryKey( resId );//
			// 通过资源Id查询资源信息
			//
			// Videos videos = videosMapper.selectByPrimaryKey(
			// resources.getResId() );
			// resourceCategorsResPo.setThumbnail( videos.getFrontCover() );
			// resourceCategorsResPo.setResType( 2 );
			// resourceCategorsResPo.setDatePx(
			// DateUtil.parseFormatToPublishDate( resources.getPublishDate() )
			// );
			// resourceCategorsResPo.setPublishDate( resources.getPublishDate()
			// );
			//
			// resourceCategorsResPo.setResId( resources.getResId() );
			// resourceCategorsResPo.setResName( resources.getResName() );
			// resourceCategorsResPo.setResTypeId( resources.getResTypeId() );
			// resourceCategorsResPo.setResCategoryId(
			// resourceCategors.getResCategoryId() );
			// resourceCategorsResPo.setResCategoryName(
			// resourceCategors.getResName() );
			//
			// // 通过资源类型id获取资源类型table
			// ResourceType queryResourceType =
			// resourceTypeMapper.selectByPrimaryKey( resources.getResTypeId()
			// );
			// resourceCategorsResPo.setResTable(
			// queryResourceType.getResTable() );
			// resourceCategorsResPo.setStatus( resources.getStatus() );
			//
			// if (!resourceCategorsResPoList.contains( resourceCategorsResPo ))
			// {
			// resourceCategorsResPoList.add( resourceCategorsResPo );
			// }
			// }
			// // 存储更新到mongo
			// if (null != resourceCategorsResPoList &&
			// resourceCategorsResPoList.size() > 0) {
			// ResourceCategorsResListMongo.addResourceCategorsResList(
			// resourceCategorsResPoList );
			// }
			// }
			// }
			// } else if (resourceType.getResTable().equals( "Games" )) {
			// // 视频和图片审核通过
			// resCateRelationsParent = new ArrayList<String>();
			// resCateRelationsChair = new ArrayList<String>();
			// resCateRelationsAll = new ArrayList<String>();
			// resourceCategorsResPoList = new
			// ArrayList<ResourceCategorsResPo>();
			// for (String resId : resIdList) {
			// List<ResCategoryRelationsVo> relationsList =
			// resCategoryRelationsMapper.getResCategoryRelationsByResId( resId
			// );
			// for (ResCategoryRelationsVo resCategoryRelations : relationsList)
			// {
			// if (!resCategoryRelations.getParentId().equals( "0" )) {
			// if (!resCateRelationsParent.contains(
			// resCategoryRelations.getParentId() )) {
			// resCateRelationsParent.add( resCategoryRelations.getParentId() );
			// }
			// }
			// if (!resCateRelationsChair.contains(
			// resCategoryRelations.getResCategoryId() )) {
			// resCateRelationsChair.add(
			// resCategoryRelations.getResCategoryId() );
			// }
			// }
			// for (String resCategoryIdChair : resCateRelationsChair) {
			// if (!resCateRelationsParent.contains( resCategoryIdChair )) {
			// resCateRelationsAll.add( resCategoryIdChair );
			// }
			// }
			//
			// // resCateRelationsAll 资源分类关系
			// // 加入缓存
			// if (null != resCateRelationsAll && resCateRelationsAll.size() >
			// 0) {
			// for (String resCateRela : resCateRelationsAll) {
			// ResourceCategorsResPo resourceCategorsResPo = new
			// ResourceCategorsResPo();
			// ResourceCategors resourceCategors =
			// resourceCategorsMapper.selectByPrimaryKey( resCateRela );
			// resources = resourcesMapper.selectByPrimaryKey( resId );//
			// 通过资源Id查询资源信息
			//
			// Games games = gamesMapper.selectByPrimaryKey(
			// resources.getResId() );
			// resourceCategorsResPo.setThumbnail( games.getFrontCover() );
			// resourceCategorsResPo.setResType( 2 );
			// resourceCategorsResPo.setDatePx(
			// DateUtil.parseFormatToPublishDate( resources.getPublishDate() )
			// );
			// resourceCategorsResPo.setPublishDate( resources.getPublishDate()
			// );
			//
			// resourceCategorsResPo.setResId( resources.getResId() );
			// resourceCategorsResPo.setResName( resources.getResName() );
			// resourceCategorsResPo.setResTypeId( resources.getResTypeId() );
			// resourceCategorsResPo.setResCategoryId(
			// resourceCategors.getResCategoryId() );
			// resourceCategorsResPo.setResCategoryName(
			// resourceCategors.getResName() );
			//
			// resourceCategorsResPo.setResTable( "Games" );
			// resourceCategorsResPo.setStatus( resources.getStatus() );
			//
			// if (!resourceCategorsResPoList.contains( resourceCategorsResPo ))
			// {
			// resourceCategorsResPoList.add( resourceCategorsResPo );
			// }
			// }
			// // 存储更新到mongo
			// if (null != resourceCategorsResPoList &&
			// resourceCategorsResPoList.size() > 0) {
			// ResourceCategorsResListMongo.addResourceCategorsResList(
			// resourceCategorsResPoList );
			// }
			// }
			// }
			// }
			//
			// }
			// }
			// }

			// 通过不同资源同步更新mongo缓存.
			String tableName = "";
			if (resourceType.getResTable().equals( "Articles" )) {
				tableName = MongoTableName.DH_ARTICLES_RESOURCE;
			} else if (resourceType.getResTable().equals( "Books" )) {
				tableName = MongoTableName.DH_BOOKS_RESOURCE;
			} else if (resourceType.getResTable().equals( "Magazines" )) {
				tableName = MongoTableName.DH_MAGAZINES_LIST;
			} else if (resourceType.getResTable().equals( "Pictures" )) {
				tableName = MongoTableName.DH_VIDEOS_LIST;
			} else if (resourceType.getResTable().equals( "Pictures" ) || resourceType.getResTable().equals( "Videos" )) {
				tableName = MongoTableName.DH_VIDEOS_LIST;
			} else if (resourceType.getResTable().equals( "Games" )) {
				tableName = MongoTableName.DH_GAMES_RESOURCE;
			} else if (resourceType.getResTable().equals( "mobile" )) {
				tableName = MongoTableName.DH_WECHAT_SHARES_RESOURCE;
			}
			ResourceCommonMongo.updateResourceStatus( resIdList, list.get( 0 ).getStatus(), tableName,
					InstitutionLoadUtils.getString( "institutionId" ) );

			// 修改门户站点中资源状态
			ResourceCategorsResListMongo
					.updateResourceStatus( resIdList, list.get( 0 ).getStatus(), InstitutionLoadUtils.getString( "institutionId" ) );

		}

		return result;
	}

	@Override
	public PagedResult<ResourcesVo> selectResourcesListNoWithRelations(ResourcesVo resourcesVo) {
		Integer pageNo = resourcesVo.getPageNumber() == null ? 0 : resourcesVo.getPageNumber();
		Integer pageSize = resourcesVo.getPageSize() == null ? 10 : resourcesVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个
		PageHelper.startPage( pageNo, pageSize );
		return BeanUtils.toPagedResult( resourcesMapper.selectResourcesListNoWithRelations( resourcesVo ) );
	}

	@Override
	public PagedResult<ResourcesVo> selectResourcesListWithRelations(ResourcesVo resourcesVo) {
		Integer pageNo = resourcesVo.getPageNumber() == null ? 0 : resourcesVo.getPageNumber();
		Integer pageSize = resourcesVo.getPageSize() == null ? 10 : resourcesVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个
		PageHelper.startPage( pageNo, pageSize );
		return BeanUtils.toPagedResult( resourcesMapper.selectResourcesListWithRelations( resourcesVo ) );
	}

	@Override
	public Integer addResourceRelations(ResourcesVo firstVo, ResourcesVo secondVo) throws Exception {
		ResourceRelations resourceRelations = new ResourceRelations();
		// 封装数据
		resourceRelations.setResRelationId( StringUtil.createSystemDataPrimaryKey() );
		resourceRelations.setFristResId( firstVo.getResId() );
		resourceRelations.setSecondResId( secondVo.getResId() );
		resourceRelations.setRelationType( 1 );
		return resourceRelationsMapper.insertSelective( resourceRelations );
	}

	@Override
	public Integer removeResourceRelations(ResourceRelationsVo record) {
		return resourceRelationsMapper.deleteByPrimaryKey( record.getResRelationId() );
	}

	/**
	 * 通过资源分类id和开始年份、结束年份、总数量限制获取非报刊资源类型订单列表.
	 * 
	 * @param orderOtherResVo
	 * @return
	 */
	@Override
	public List<OrderResultVo> getResourcesListByRescategorsIdOrYear(OrderOtherResVo orderOtherResVo) {
		return resourcesMapper.getResourcesListByRescategorsIdOrYear( orderOtherResVo );
	}

	/**
	 * 通过订单资源分类id、开始年份、预定结束年份、预定个数限制获取非连续出版物类型资源列表.
	 * 
	 * @param orderExportOtherResQueryVo
	 * @return
	 */
	@Override
	public List<Resources> getOrderOtherResourcesListByResCategoryId(OrderExportOtherResQueryVo orderExportOtherResQueryVo) {
		return resourcesMapper.getOrderOtherResourcesListByResCategoryId( orderExportOtherResQueryVo );
	}

	/**
	 * 通过资源类型id获取已关联资源类型的资源列表.
	 */
	@Override
	public List<Resources> getResourcesListByResTypeId(String resTypeId) {
		return resourcesMapper.getResourcesListByResTypeId( resTypeId );
	}

	@Override
	public Integer getResourcesListStatusCount() {
		return resourcesMapper.getResourcesListStatusCount();
	}

	/**
	 * 通过订单中的期刊id获取所有有关联的文章列表.
	 * 
	 * @param resId
	 * @return
	 */
	@Override
	public List<Resources> getOrderResourcesListByMagazinesId(String resId) {
		return resourcesMapper.getOrderResourcesListByMagazinesId( resId );
	}

	/**
	 * 通过订单中的期刊id获取所有有关联的文章列表.
	 * 
	 * @param resId
	 * @return
	 */
	@Override
	public List<Resources> getOrderResourcesListByMagazinesIdNew(ResourcesVo resourcesVo) {
		return resourcesMapper.getOrderResourcesListByMagazinesIdNew( resourcesVo );
	}

	@Override
	public Integer getCharResourcesListCount(List<String> list) {
		return resourcesMapper.getCharResourcesListCount( list );
	}
}